﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Gunningine
{
    /// <summary>
    /// Emitted implementations are defined in script, and when loaded in, we
    /// create a Battery implementation for each type, with specialised Emit
    /// method based on the subclass's constructor.  Maybe also transform the
    /// Frame/Run methods so that they are inlined within the loop?
    /// </summary>
    public abstract class Emitted
    {
        public Vector3 Position { get; set; }

        internal Entity Owner { get; set; }

        internal bool Alive { get; set; }

        /// <summary>
        /// Constructor.
        /// </summary>
        public Emitted()
        {
            this.Alive = true;
        }

        /// <summary>
        /// Kill this object.
        /// </summary>
        protected void Die()
        {
            this.Alive = false;
        }

        /// <summary>
        /// Run once per frame.
        /// </summary>
        /// <param name="frameTime"></param>
        protected abstract void Frame(float frameTime);

        /// <summary>
        /// Update function (coroutine).
        /// </summary>
        protected abstract void Run(float frameTime);

        /// <summary>
        /// Update object each frame.
        /// </summary>
        /// <param name="frameTime"></param>
        internal void Update(float frameTime)
        {
            Frame(frameTime);
            Run(frameTime);
        }
    }
}
